// TypeScript file
module Bullet {
    /**子弹类型*/
    enum BulletType { "b1_png", "b2_png", "b3_png" };
    /**
     * 子弹基础---郭启航
     */
    export class BasicBullet {

        /**初始化子弹*/
        public initBullet(showPanle, bulletManager, type) {
            this.bulletManager = bulletManager;
            this.bulletType = type;
            this.showPanle = showPanle;
            this.createBulletTexture();
            this.getConfig();
        }
        /**子弹*/
        public bullet: egret.Bitmap;
        /**子弹唯一标识*/
        public bulletId: number;
        /**子弹类型*/
        public bulletType: number;
        /**显示容器*/
        public showPanle: egret.DisplayObjectContainer;
        /**子弹管理容器*/
        public bulletManager: Bullet.BulletManager;
        /**子弹血量*/
        public bulletHp: number;

        /**子弹速度*/
        public bulletSpeed: number;
        /**子弹角度*/
        public Angle: number;
        /**记录子弹伤害*/
        public bulletATK: number;
        /**子弹是否显示在舞台上*/
        public bulletIsLiving: boolean = false;
        /**读取子弹配置*/
        public getConfig() {
            this.bulletHp = GameUtil.PlayerMessage.createMsg().bulletConfig[this.bulletType].Hp;
            //console.log(this.bulletHp);
            this.bulletATK = GameUtil.PlayerMessage.instance.bulletConfig[this.bulletType].ATK;
            this.bulletSpeed = GameUtil.PlayerMessage.instance.bulletConfig[this.bulletType].Speed;
        }

        /**确认子弹位图*/
        public createBulletTexture() {
            if (this.bullet == null) {
                this.bullet = new egret.Bitmap();
                this.bullet.addEventListener(egret.Event.REMOVED_FROM_STAGE,this.removeFromStage,this);
            }
            this.bullet.texture = RES.getRes(BulletType[this.bulletType]);
        }


        /**确认子弹出生位置*/
        public bulletBorn(point: egret.Point, tid, angle) {
            this.bullet.x = point.x;
            this.bullet.y = point.y;
            this.bulletId = tid;
            this.Angle = angle;
            this.showPanle.addChild(this.bullet);
            this.bulletIsLiving = true;
            this.bullet.visible = true;

        }
        /**子弹销毁 */
        public destory() {
            this.bulletManager.destoryOneBullet(this.bulletId);
            if (this.bullet.parent) {
                this.bullet.parent.removeChild(this.bullet);
            }
        }
        /**子弹飞出舞台 */
        public overLine() {
            this.bulletIsLiving = false;
            this.bullet.visible = false;
            this.destory();
        }
        /**子弹每帧运行*/
        public update(deltaTimeStamp) {
            this.bulletMove(deltaTimeStamp);
            if (this.bullet.y > 1136 || this.bullet.y < 0) {
                this.overLine();
            }
            if (this.bulletHp <= 0) {
                this.destory();
            }
        }
        /**子弹移动*/
        public bulletMove(deltaTimeStamp: number) {
            this.bullet.y -= this.bulletSpeed;
        }
        /**飞机子弹运动方式*/
        protected BulletToPoint(targePoint: egret.Point) {

        }
        /**离开舞台 */
        public removeFromStage()
        {
            GameUtil.GamePools.instance.reclaimBlt(this);
        }
    }
}